<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.action.WriteProblemAction"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.model.JobPost"%>
<%@page import="com.shsh.safemanage.dao.TitlePostManageGroupDao"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.dao.UserDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.ProblemTransfer"%>
<%@page import="com.shsh.safemanage.model.ProblemTransferFeedback"%>
<%@page import="com.shsh.safemanage.model.Problem"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.model.Shutdown"%>
<%@page import="com.shsh.safemanage.model.ShutdownType"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.ProblemDao"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>

<%
	session.removeAttribute(Constants.SESSION_ESCALATE_USER);
	session.removeAttribute(Constants.SESSION_MANAGE_GROUP_USER);
	session.removeAttribute(Constants.SESSION_PROBLEM_DEPARTMENT1);

String problemIDStr = request.getParameter(Constants.REQUEST_PARAMETER_ID);
Long problemID = 0L;
try {
	problemID = new Long(problemIDStr);
} catch (Exception e) {
}

String transferIDStr = request.getParameter(Constants.REQUEST_PARAMETER_TRANSFER_ID);
Long transferID = null;
try {
	transferID = new Long(transferIDStr);
} catch (Exception e) {
}

String fromPage = request.getParameter(Constants.REQUEST_PARAMETER_FROM_PAGE);
String backPage = request.getContextPath()+"/shutdown/shutdown_browse.jsp";
if(Constants.FROM_PAGE_PROBLEMS_TOBE_PROCESSED.equals(fromPage)){
	backPage = request.getContextPath()+"/problems_tobe_processed.jsp";
} else if (Constants.FROM_PAGE_SUPERVISE_PAGE.equals(fromPage)) {
	backPage = request.getContextPath() + "/problems_tobe_processed_supervise.jsp";
} else if (Constants.FROM_PAGE_YIBAN_PAGE.equals(fromPage)){
	backPage = request.getContextPath()+"/problem_browse.jsp";
}

DepartmentDao departmentDao = DaoCreator.createDepartmentDao();
ProblemDao problemDao = DaoCreator.createProblemDao();
UserDao userDao = DaoCreator.createUserDao();

TitlePostManageGroupDao titlePostManageGroupDao = DaoCreator.createTitlePostManageGroupDao();
WriteProblemAction writeProblemAction = ActionCreator.createWriteProblemAction();
UserAction userAction = ActionCreator.createUserAction();

Shutdown problem = problemDao.getShutdownByID(problemID);
String problemName = Shutdown.getProblemName(problem.getProblemType());

int[] periodStart = Util.getDate(problem.getPeriodStart());
int[] periodEnd = Util.getDate(problem.getPeriodEnd());

long periodMinutes = problem.getPeriodMinutes();
long[] periodLength = problem.getPeriodLength();

List<ProblemTransferFeedback> feedbackList = problemDao.getProblemTransferFeedbackByProblemID(problemID);

User user = userDao.getUserByID(problem.getShutdownWriteUserID());
JobPost post1 = titlePostManageGroupDao.getJobPostByID(user.getJobPost1ID());
JobPost post2 = titlePostManageGroupDao.getJobPostByID(user.getJobPost2ID());
JobPost post3 = titlePostManageGroupDao.getJobPostByID(user.getJobPost3ID());
Role theRole = userAction.getUserRole(request);

int role = writeProblemAction.calRole(post1, post2, post3, theRole);

List<ShutdownType> shutdownTypeList = problemDao.getShutdownTypeList();
ProblemTransfer currentTransfer = problemDao.getProblemTransfer(problem.getWriteUserID(), problemID, user.getId());
if(currentTransfer != null){
	transferID = currentTransfer.getId();
}
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; <%=problemName %>浏览 
</div>

<div class="tt">《高桥石化公司<%=problemName %>报告》</div>
<div class="content">
	<table align="center" border="1" width="99%" cellpadding="0"
		cellspacing="0">
	<tr>
		<td class="td1" colspan="2">
			<span style="margin-left: 30px; font-weight: bold">流程跟踪：</span>
			<br />
			<span style="margin-left: 50px; color: red">
			<%=Util.formatDateTime(problem.getWriteTime())%> <%=problem.getWriteUserName()%> 填报问题
			</span>
			<%
			for (ProblemTransferFeedback feedback : feedbackList) {
			%>
			<br />
			<span style="margin-left: 50px; color: red">
			<%=Util.formatDateTime(feedback.getFeedbackTime())%>
			<%
			User theFeedbackUser = userDao.getUserByID(feedback.getUserID());
			%>
			<%=theFeedbackUser.getName()%>
			<%=feedback.getProcessMethodStr()%>
			</span>
			<%
			}
			%>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span style="margin-left: 30px; font-weight: bold">作业部（业务中心）：</span> <span><%=problem.getDepartment1Name()%></span>
			<span style="margin-left: 30px; font-weight: bold">装置：</span> <span><%=problem.getEquipmentName()%></span>
			<span style="margin-left: 30px; font-weight: bold"><%=problemName %>性质：</span> <span><%=problem.getShutdownType()%></span>
<%
if(problem.getProblemType() == Constants.PROBLEM_TYPE_NOTPLANED_SHUTDOWN) {
%>
				<span style="margin-left: 30px; font-weight: bold">
					<input disabled="disabled" type="checkbox" id="escalateZongbu" name="escalateZongbu" value="true" <%=problem.getEscalateZongbu()!=null&&problem.getEscalateZongbu()?"checked=\"checked\"":"" %>/>
					<label for="escalateZongbu">上报总部</label>
				</span>
<%
}
%> 
		</td>
	</tr>
	<tr>
			<td class="td1" width="60%">	
			<table width="100%">
			<tr>
				<td rowspan="2">
				<span style="margin-left: 30px; font-weight: bold"><%=problemName %>时间段：</span> 
				</td>
				<td>		
				<span style="margin-left: 10px; ">						
						<input style="margin-left: 30px; width:35px;" readonly="readonly" type="text" value="<%=periodStart[0] %>"/>年	
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodStart[1] %>"/>月	
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodStart[2] %>"/>日
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodStart[3] %>"/>时
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodStart[4] %>"/>分
				</span>	
				</td>
			</tr>
			<tr>
			<td>
				<span style="margin-left: 10px; ">	
						<input style="margin-left: 30px; width:35px;" readonly="readonly" type="text" value="<%=periodEnd[0] %>"/>年	
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodEnd[1] %>"/>月	
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodEnd[2] %>"/>日
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodEnd[3] %>"/>时
						<input style="margin-left: 5px; width:25px;" readonly="readonly" type="text" value="<%=periodEnd[4] %>"/>分
				</span>	
			</td>
			</tr>
			</table>
			</td>
			<td  class="td1" width="40%">
				<span style="margin-left: 30px; font-weight: bold"><%=problemName %>时间：</span> 
				共<input  style="margin-left: 0px; width:50px;" readonly="readonly" type="text" id="periodMinutes" value="<%=periodMinutes%>"/>分钟
				<br/>
				<input  style="margin-left: 30px; width:35px;" readonly="readonly" type="text" id="periodDay"value="<%=periodLength[0]%>"/>天
				<input  style="margin-left: 5px; width:25px;" readonly="readonly" type="text" id="periodHour" value="<%=periodLength[1]%>"/>小时
				<input  style="margin-left: 5px; width:25px;" readonly="readonly" type="text" id="periodMinute" value="<%=periodLength[2]%>"/>分钟
			</td>
	</tr>
	<tr>
			<td class="td1" colspan="2">			
				<span style="margin-left: 30px; font-weight: bold"><%=problemName %>名称：</span>  <br/>
				<span style="margin-left: 30px; ">
						<textarea readonly="readonly" rows="3" style="width:90%;" id="problemTitle"><%=problem.getProblemTitle()%></textarea>	
				</span>	
			</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold"><%=problemName %>经过：</span> <br/>
			<span style="margin-left: 30px; ">
			<textarea readonly="readonly" rows="5" style="width:90%;" id="problemContent"><%=problem.getProblemContent()%></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold">直接经济损失与间接经济损失：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea readonly="readonly" rows="5" style="width:90%;" id="loss"><%=problem.getLoss()%></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold"><%=problemName %>原因：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea readonly="readonly" rows="10" style="width:90%;" id="reason"><%=problem.getReason()%></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold"><%=problemName %>教训及防范措施：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea readonly="readonly" rows="10" style="width:90%;" id="zhenggai_cuoshi"><%=problem.getProblemZhenggai()%></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold"><%=problemName %>责任分析及处理情况：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea readonly="readonly" rows="10" style="width:90%;" id="duty"><%=Util.isNullOrEmpty(problem.getDuty())?"":problem.getDuty()%></textarea>	
			</span>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2"><span
			style="margin-left: 30px; font-weight: bold"><%=problemName %>调查小组人员名单：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
			<textarea readonly="readonly" rows="5" style="width:90%;" id="team"><%=Util.isNullOrEmpty(problem.getTeam())?"":problem.getTeam()%></textarea>	
			</span>
		</td>
	</tr>
		<tr>
			<td class="td1" colspan="2">
				<span style="margin-left: 30px" class="span1">填报人及时间：</span>
				<span><%=user.getDepartment1Name()%>-<%=user.getDepartment2Name()%>-<%=user.getDepartment3Name()%></span>
				<span><%=user.getName()%></span>
				<span><%=Util.formatDateTime(problem.getShutdownWriteTime())%></span>
			</td>
		</tr>
		<tr>
			<td class="td1" align="center" colspan="2">
				<input type="button" value="关 闭" style="margin-left: 20px" onclick="closeRead()" />
			</td>
		</tr>
	</table>
</div>
<div id="selectDepart1Div" style="display: block;">
<%@include file="/shutdown/select_depart1ID_section.jsp" %>
</div>
<script type="text/javascript">
var shutdownTypes = new Array();
<%
for (ShutdownType type : shutdownTypeList) {
%>
shutdownTypes.push("<%=type.getId()%>_<%=type.getDepartment1ID()%>");
<%
}
%>
function closeRead() {
	loadPageSection('<%=backPage%>', 'mainContentDiv', {fromPage: 'feedback', problemType: <%=problem.getProblemType()%>}, true);
}

</script>
